package com.mashibing.controller;

import com.mashibing.internalcommon.dto.OrderInfo;
import com.mashibing.mapper.OrderInfoMapper;
import com.mashibing.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class TestController {

    @Autowired
    private OrderInfoMapper mapper;

    @Autowired
    private OrderService orderService;

    @Value("${server.port}")
    private String port;

    @GetMapping("/test")
    public String test() {
        return "成功";
    }

    @GetMapping("/addTest")
    public String addTest() {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setAddress("测试案例");
        mapper.insert(orderInfo);
        return orderInfo.getAddress();
    }

    @GetMapping("/jmterTest/{orderInfoId}")
    public void jmterTest(@PathVariable String orderInfoId) {
        System.out.println("请求地址port:" + port + ",orderInfoId=" + orderInfoId);

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setDepLatitude("31.185296");
        orderInfo.setDepLongitude("121.713396");
        orderInfo.setId(Long.valueOf(orderInfoId));
        orderService.dispatchOrder(orderInfo);
    }

    @PostMapping("/dispatchOrderTest")
    public void dispatchOrderTest(@RequestBody OrderInfo orderInfo) {
        orderService.dispatchOrder(orderInfo);
    }
}
